import os

time_suffix = '_2024q1'
time_suffix_2 = '2024-q4'
time_p_mon = """
'202401','202402','202403'
"""
time_p_day = """
'20241001', '20241004', '20241007', '20241010', '20241013', '20241016', '20241019', '20241022',
'20241025', '20241028', '20241101', '20241104', '20241107', '20241110', '20241113', '20241116',
'20241119', '20241122', '20241125', '20241128', '20241201', '20241204', '20241207', '20241210',
'20241213', '20241216', '20241219', '20241222', '20241225', '20241228'
"""

file_path = './template/出入港相关-temp.sql'
output_dir = './output' + time_suffix
output_path = output_dir + '/出入港相关' + time_suffix + '.sql'
replace_dict = {
    '***1': time_suffix,
    '***2': time_p_mon,
    '***3': time_suffix_2,
    '***4': time_p_day,
}

os.makedirs(output_dir, exist_ok=True)

# 读取文件内容并替换
with open(file_path, 'r', encoding='utf-8') as f:
    content = f.read()

# 替换指定内容
for k, v in replace_dict.items():
    print(v)
    content = content.replace(k, v)

with open(output_path, 'w', encoding='utf-8') as f:
    f.write(content)

print("替换完成，输出写入", output_path)